#pragma once
#include "GameApplication.h"
#include "Cube.h"

class Cube;

class PipeCube: public Cube
{
	private:
		int degreesRotated;			//How many degrees this Cube has rotated, reset to 0 when the Cube is done rotating
		bool isRotating;			//Is the block rotating?
		bool rotatingLeft;			//Is it rotating left?
		bool rotatingRight;			//Is it rotating right?
		bool rotatingForward;		//Is it rotating forward?
		bool rotatingBackward;		//Is it rotating backward?
		bool rotatingClock;			//Is it rotating clockwise (y-axis)?
		bool rotatingCountClock;	//Is it rotating counter-clockwise (y-axis)?
		std::string materials[6];
		
		bool faces[6][3][3];	//The mapping of faces of a Cube, the outermost array represents the different faces of a Cube
		//The two innermost vectors represent the connectivity of a Cube (Is the Cube connected to the north? south? east?... etc.)
		//For now, we'll say that faces[0] is the face that faces up when the Cube is created, faces[1] is the face rotated to the left
		//faces[2] is the face on the opposite side of face[0] and face[3] is the face that shows when rotated to the right from face[0]
		//face[3] is also opposite of face[1].  face[4] is the face of the Cube that results in rotating face[0] forward and face[5] is opposite face[4]
		//and results from rotating backward from face[0]
		//The mappings of the faces are as follows:

		//face[0] -> left -> face[1]				face[1] -> left -> face[2]				face[2] -> left -> face[3]
		//		  -> right -> face[3]						-> right -> face[0]						-> right -> face[1]
		//		  -> forward -> face[4]						-> forward -> face[4]					-> forward -> face[4]
		//        -> backward -> face[5]					-> backward -> face[5]                  -> backward -> face[5]

		//face[3] -> left -> face[0]				face[4] -> left -> face[1]				face[5] -> left -> face[3]
		//		  -> right -> face[2]						-> right -> face[3]						-> right -> face[1]
		//        -> forward -> face[4]						-> forward -> face[2]					-> forward -> face[0]
		//        -> backward -> face[5]					-> backward -> face[0]					-> backward -> face[2]
		/*
			A cube can be thought of starting as looking like this:
				+---+
				| 5 |	<---Backward
			+---+---+---+
Right--->	| 3 | 0 | 1 |	<---Left
			+---+---+---+
			    | 4 |	<---Forward
				+---+
				| 2 |	<---Bottom
				+---+
		*/

		int currentFace;								//The current face showing to the player
		int facePlaceHolder[6];							//This shows how the faces are currently are on the cube
		void initializeFaces();							//Initialize the different faces of this cube randomly
		void rotateFace( int which, bool clockwise );	//Rotate the "which" clockwise or counterclickwise depending on the value passed
		void rotateFacePlaceHolder(char axis, bool clockwise);
		void figureOutTextures(int face, int p1x, int p1y, int p2x, int p2y);	//This is a helper method to be used in initializeFaces(), it simply makes the code look neater
									//This applies the correct texture to the numbered face:  0 = A, 1 = B, 2 = C, 3 = D, 4 = E, 5 = F
		/*
		void rotateXFacePlaceHolder(bool clockwise);	//Rotate facePlaceHolder about the x-axis clockwise or counterclockwise depending on value passed
		void rotateYFacePlaceHolder(bool clockwise);	//Rotate facePlaceHolder about the y-axis clockwise or counterclockwise depending on value passed
		void rotateZFacePlaceHolder(bool clockwise);	//Rotate facePlaceHolder about the z-axis clockwise or counterclockwise depending on value passed
		*/

		std::list<Ogre::MaterialPtr> pipeMaterials;

	public:
		PipeCube(Ogre::Vector3 location, GridNode* g, std::list<Ogre::MaterialPtr> materials, Ogre::MeshPtr cubePtr, int iD = -1, Ogre::SceneNode* mySceneNode = NULL, int direction = -1);	//This is for use with ObstacleCube.changeToPipeCube()
		void rotateLeft();			//Rotates the cube left, according to camera position
		void rotateRight();			//Rotates the cube right, according to camera position
		void rotateForward();		//Rotates the cube forward (away from the player), according to camera position
		void rotateBackward();		//Rotates the cube backward (toward the player), according to camera position
		void rotateClock();			//Rotates the cube clockwise (on the y-axis), according to camera position
		void rotateCountClock();	//Rotates the cube counter-clockwise (on the y-axis), according to camera position
		void update(Ogre::Real deltaTime); //Updates the rotation and possibly other things related to this type of cube
		void updateRotate(Ogre::Real deltaTime); //Using this instead of cluttering the update() routine with a bunch of code
		int* getCurrentFace();	//Returns the integers in the format [y1,x1,y2,x2] that represent where the faces have entrances and exits.  This will only be of size 4
		//HouseCube* changeToHouseCube();
		void hideAllTextures();
		void showAllTextures();
};